#include "include.h"

bit led1_bit = 0;
bit led2_bit = 0;
bit led3_bit = 0;
bit led4_bit = 0;
bit led5_bit = 0;

//mybits led_data;


void led_all_off(void)
{
	led1_bit = 0;
	led2_bit = 0;
	led3_bit = 0;
	led4_bit = 0;
	led5_bit = 0;
}

void led_display(void)	// 10ms
{
	#if(LED_TEST)
	led1_bit = 1;
	led2_bit = 1;
	led3_bit = 1;
	led4_bit = 1;
	led5_bit = 1;
	return;
	#else
	static u8 blink_time = 0;
	static bit led_toggle_flag;
	
	led_toggle_flag = 0;
	blink_time++;
	if(blink_time >= 50)
	{
			blink_time = 0;
		led_toggle_flag = 1;
	}
	
	if(FlagPairEnable)
	{
		
		if(led_toggle_flag)
		{
			
			led1_bit = ~led1_bit;
			led2_bit = ~led2_bit;
			led3_bit = ~led3_bit;
			led4_bit = ~led4_bit;
			led5_bit = ~led5_bit;
		}
	}
	else
	{
		
		if(host_exist_flag)
		{
			if(FlagCaliEn || M2_mode == M2_RESET)
			{
				if(led_toggle_flag) led1_bit = ~led1_bit;
			}
			else
			{
				if(gTrigStatus) led1_bit = 1; else {
					//if(M2_mode == M2_RESET) led1_bit = 1; else led1_bit = 0;
					led1_bit = 0;
				}
			}
			
			if(gBrakeStatus)
			{
				led2_bit = 0;	//led2_bit = 1;
			}
			else
			{
				led2_bit = 0; //led2_bit = 0;
			}
			
			if(M2_mode == M2_FULLBACK)
			{
				led3_bit = 1;
				led4_bit = 0;
				led5_bit = 0;
			}
			else if(M2_mode == M2_UPBACK)
			{
				led3_bit = 0;
				led4_bit = 1;
				led5_bit = 0;
			}
			else if(M2_mode == M2_DOWNBACK)
			{
				led3_bit = 0;
				led4_bit = 0;
				led5_bit = 1;
			}
			else
			{
				led3_bit = 0;
				led4_bit = 0;
				led5_bit = 0;
			}
			
		}
		else
		{
			led_all_off();
		}
	}
	
	#endif

}
